<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
            box-sizing: border-box;
        }

        .box {
            width: 300px;
            height: 200px;
            border: 1px solid #000;
            margin: auto;
        }

        .box>.head {
            display: flex;
            justify-content: space-between;
        }

        .box>.head>li {
            flex-grow: 1;
            text-align: center;
            cursor: pointer;
        }

        .active {
            background-color: #87ceeb;
        }

        .main {
            position: relative;
        }

        .main>li {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 178px;
            background-color: #87ceeb;
        }

        .mainActive {
            z-index: 999;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul class="head">
            <li class="active">标题一</li>
            <li>标题二</li>
            <li>标题三</li>
        </ul>

        <ul class="main">
            <li class="mainActive">内容一</li>
            <li>内容二</li>
            <li>内容三</li>
        </ul>
    </div>
    <script>
        let li1 = document.querySelectorAll(".head li");
        let li2 = document.querySelectorAll(".main li");
        for (let i = 0; i < li1.length; i++) {
            li1[i].onclick = function () {
                for (let j = 0; j < li1.length; j++) {
                    li1[j].className = '';
                    li2[j].className = '';
                }
                li1[i].classList.toggle('active');
                li2[i].classList.toggle('mainActive');
            }

        }
////////////不会。。同学代码照抄的。。有空开开小灶。。///////////
    </script>
</body>

</html>